var menuFn={
	_variable:{
		papers:["main.jpg","bg01.html","bg02.html","bg03.html","bg04.html","bg05.html","bg06.html","bg07.html"]
	},
	_util:{
		addShotCut:function(appname){//发送到桌面
			var apps=win._variable.options.start_apps;
			for(var i in apps){
				if(apps[i].name==appname.trim()){
					if(apps[i].shortcut.is){
						win._toast("提示",apps[i].name+"已存在");
					}else{
						apps[i].shortcut.is=true;
						apps[i].shortcut.order=win._util.getShortcuts().length;
						win._toast("提示",apps[i].name+"添加成功");
						win._initShortcuts();
						break;
					}
				}
			}
		},
		addStartTile:function(appname){//发送到磁贴
			var apps=win._variable.options.start_apps;
			for(var i in apps){
				if(apps[i].name==appname.trim()){
					if(apps[i].start_tile.is){
						win._toast("提示",apps[i].name+"已存在");
					}else{
						apps[i].start_tile.is=true;
						apps[i].start_tile.order=win._util.getStartTiles().length;
						win._toast("提示",apps[i].name+"添加成功");
						win._initStartTiles();
						break;
					}
				}
			}
		}
	},
	_stopPropagation:function(){
		window.event.stopPropagation();
	},
	_enterFullScreen: function() {//进入全屏
		var doc = document.documentElement;
		//W3C
		if(doc.requestFullscreen) {
			doc.requestFullscreen();
		}
		//FireFox
		else if(doc.mozRequestFullScreen) {
			doc.mozRequestFullScreen();
		}
		//Chrome
		else if(doc.webkitRequestFullScreen) {
			doc.webkitRequestFullScreen();
		}
		//IE11
		else if(doc.msRequestFullscreen) {
			document.body.msRequestFullscreen();
		}
	},
	_exitFullScreen: function() {//退出全屏
		if(document.exitFullscreen) {
			document.exitFullscreen();
		} else if(document.mozCancelFullScreen) {
			document.mozCancelFullScreen();
		} else if(document.webkitCancelFullScreen) {
			document.webkitCancelFullScreen();
		} else if(document.msExitFullscreen) {
			document.msExitFullscreen();
		}
	},
	_nextPaper:function(){//下一个桌面壁纸
		var bgImg=win._variable.options.bgImg;
		var papers=menuFn._variable.papers;
		var index=$.inArray(bgImg,papers);
		var next=index+1;
		if(next==papers.length){
			next=0;
		}
		bgImg=menuFn._variable.papers[next];
		win._variable.options.bgImg=bgImg;
		win._initBg();
		
	},
	_app2shortcut:function(){//程序列表 发送到桌面
		var ele=win._variable.contextMenuElement;
		var appname=$(ele).find("span").text();
		menuFn._util.addShotCut(appname);
	},
	_tile2shortcut:function(){//磁贴 发送到桌面
		var ele=win._variable.contextMenuElement;
		var appname=$(ele).find(".appname").text();
		menuFn._util.addShotCut(appname);
	},
	_app2startTile:function(){//程序列表 发送到磁贴
		window.event.stopPropagation();
		$("#context_menu").hide();
		var ele=win._variable.contextMenuElement;
		var appname=$(ele).find("span").text();
		menuFn._util.addStartTile(appname);
	},
	_resizeTile:function(size){//调整磁贴大小
		window.event.stopPropagation();
		$("#context_menu").hide();
		var ele=win._variable.contextMenuElement;
		var appname=$(ele).find(".appname").text();
		var app=win._util.getApp(appname);
		app.start_tile.size=size;
		ele.removeClass("tile-1").removeClass("tile-2").removeClass("tile-3").addClass("tile-"+size);
	},
	_activeTile:function(active){//是否开启动态磁贴
		window.event.stopPropagation();
		$("#context_menu").hide();
		var ele=win._variable.contextMenuElement;
		var appname=$(ele).find(".appname").text();
		var app=win._util.getApp(appname);
		if (active) {
			active=true;
		} else{
			active=false;
		}
		app.start_tile.live=active;
		win._initStartTiles();
	},
	_shortcutMv:function(num){//移动桌面快捷方式
		var ele=win._variable.contextMenuElement;
		$("#context_menu").hide();
		var appname=$(ele).find("span").text();
		var shortcuts=win._util.getShortcuts();
		var order=0;
		for(var i=0;i<shortcuts.length;i++){
			if(shortcuts[i].name==appname){
				order=i;
				break;
			}
		}
		if((num+order)>shortcuts.length-1){
			win._toast("提示","操作失败，"+appname+"无法向后移动");
			return;
		}
		if(num+order<0){
			win._toast("提示","操作失败，"+appname+"无法向前移动");
			return;
		}
		shortcuts[order].shortcut.order=order+num;
		shortcuts[order+num].shortcut.order=order;
		win._initShortcuts();
	},
	_tileMv:function(num){//移动动态磁贴
		var ele=win._variable.contextMenuElement;
		$("#context_menu").hide();
		var appname=$(ele).find(".appname").text();
		var tiles=win._util.getStartTiles();
		var order=0;
		for(var i=0;i<tiles.length;i++){
			if(tiles[i].name==appname){
				order=i;
				break;
			}
		}
		if((num+order)>tiles.length-1){
			win._toast("提示","操作失败，"+appname+"无法向后移动");
			return;
		}
		if(num+order<0){
			win._toast("提示","操作失败，"+appname+"无法向前移动");
			return;
		}
		tiles[order].start_tile.order=order+num;
		tiles[order+num].start_tile.order=order;
		win._initStartTiles();
	},
	_shortcutRm:function(){
		var ele=win._variable.contextMenuElement;
		$("#context_menu").hide();
		var appname=$(ele).find("span").text();
		var shortcuts=win._util.getShortcuts();
		for(var i=0;i<shortcuts.length;i++){
			if(shortcuts[i].name==appname){
				shortcuts[i].shortcut.is=false;
				break;
			}
		}
		win._initShortcuts();
	},
	_tileRm:function(){
		window.event.stopPropagation();
		var ele=win._variable.contextMenuElement;
		$("#context_menu").hide();
		var appname=$(ele).find(".appname").text();
		var shortcuts=win._util.getShortcuts();
		var tiles=win._util.getStartTiles();
		for(var i=0;i<tiles.length;i++){
			if(tiles[i].name==appname){
				tiles[i].start_tile.is=false;
				break;
			}
		}
		ele.remove();
	}
}
